package com.wyp.demo.pattern.proxy.dynamic;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

/**
 * 生成代理类
 *
 * @author: Oliver
 * @time: 2020/12/20/10:59
 */
public class ProxyUtil {

    public static <T> T newProxyInstance(T target, InvocationHandler handler) {
        ClassLoader classLoader = target.getClass().getClassLoader();
        Class<?>[] interfaces = target.getClass().getInterfaces();
        return (T) Proxy.newProxyInstance(classLoader, interfaces, handler);
    }
}
